﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

/// <summary>
/// Summary description for renewDAL
/// Description: For insurance renew
/// Author : HUANG JIFEN  
/// Created: 27 July 2013
/// </summary>
public class RenewDAL
{
	public RenewDAL()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public void renew(int currentInsuredID)
    {
        

        String sql = "insert into INSURED (" +
                                "accountNo," +
                                "fName," +
                                "lName," +
                                "NRIC," +
                                "nationality," +
                                "gender," +
                                "marital," +
                                "birth," +
                                "relationship," +
                                "planType," +
                                "PremiumLevel," +
                                "occupation," +
                                "telephone," +
                                "longStay," +
                                "mobile," +
                                "email," +
                                "address," +
                                "postalCode," +
                                "employerName," +
                                "employerAddress," +
                                "business," +

                                "illness," +
                                "illDuration," +
                                "illTreatment," +
                                "illhospital," +
                                "DeclinedHistory," +
                                "foreseeable," +
                                "bloodPressureIllSystolic," +
                                "bloodPressureIllDate," +
                                "bloodPressureIllHospital," +
                                "HyperlipidaemiaLevel," +
                                "HyperlipidaemiaDate," +
                                "HyperlipidaemiaHospital," +

                                "Premium," +
                                "policyStatus," +
                                "startDate," +
                                "endDate" +


        ")" +

        "select " +
                                "accountNo," +
                                "fName," +
                                "lName," +
                                "NRIC," +
                                "nationality," +
                                "gender," +
                                "marital," +
                                "birth," +
                                "relationship," +
                                "planType," +
                                "PremiumLevel," +
                                "occupation," +
                                "telephone," +
                                "longStay," +
                                "mobile," +
                                "email," +
                                "address," +
                                "postalCode," +
                                "employerName," +
                                "employerAddress," +
                                "business," +

                                "illness," +
                                "illDuration," +
                                "illTreatment," +
                                "illhospital," +
                                "DeclinedHistory," +
                                "foreseeable," +
                                "bloodPressureIllSystolic," +
                                "bloodPressureIllDate," +
                                "bloodPressureIllHospital," +
                                "HyperlipidaemiaLevel," +
                                "HyperlipidaemiaDate," +
                                "HyperlipidaemiaHospital," +

                                "Premium," +
                                "'ACTIVE'," +
                                "DATEADD(DAY, 1, endDate)," +
                                "DATEADD(Year, 1, DATEADD(DAY, 1, endDate)) " +

                            " from INSURED where insuredId=" + currentInsuredID;

                              

                                var conn = DBManager.getSqlConnection();
                                conn.Open();
                                var cmd = new SqlCommand(sql, conn);

                                cmd.ExecuteNonQuery();

                                sql = "UPDATE INSURED SET policyStatus = 'EXPIRED' WHERE insuredID = @insuredID";
                                
                                cmd = new SqlCommand(sql, conn);
                                cmd.Parameters.AddWithValue("@insuredID", currentInsuredID);

                                cmd.ExecuteNonQuery();

                                conn.Close();

    }


}